// String Library - by LeeZH
//      A small collection of useful code related to manipulating strings.
//
// If you want this code in any license besides GPLv3 (which the rest of
// the Checkmate source code is under), just ask me at lee@leezh.net.

#include <string>
#include <vector>

namespace stringlib
{
    // Tokenises a text into seperate strings in which delimiters in quotes are
    // ignored. The escape character is used only for preventing escaped quotes
    // to be interpreted literally.
    // For CSV files, you could use this:
    // tokenise(text, tokenlist, ",", "\"");
    void tokenise(std::string text, std::vector<std::string> &tokenList, std::string delimiters = " \t\n", std::string quotes = "\"\'", char escape = '\\', bool stripQuotes = true);

    // Strip the quote marks and anything outside. It ignores the stripped quotes
    // and does not modify if the quote marks are not closed or are non-existent.
    void stripQuoteMarks(std::string &text, std::string quotes = "\"\'", char escape = '\\');

    // Escapes/unescapes characters in C/C++ style. Currently, only the following
    // are supported:
    //  \'   Single quote
    //  \”   Double quote
    //  \\   Backslash
    //  \a   Audible bell
    //  \n   Newline
    //  \r   Carriage return
    //  \t   Horizontal tab
    //  \v   Vertical tab
    void escape(std::string &text);
    void unescape(std::string &text);
}

namespace arg
{
    bool check(std::vector<std::string> &list, std::string functionName, unsigned int minimumArgs);
    bool option1(std::vector<std::string> &list, std::string test);
    bool option2(std::vector<std::string> &list, std::string test, std::string &result);
    bool final(std::vector<std::string> &list, std::string &result, bool extracheck = true);
    bool final(std::vector<std::string> &list);
}
